package com.ruoyi.book.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.book.service.HttpApiService;

import java.util.List;

/**
 * @Author Huang dun
 * @Description //TODO
 * @Date 2025/3/31 15:05
 **/
@RestController
@RequestMapping("/book/api")
@Api(tags = "API调用管理")
public class HttpApiController extends BaseController{

    @Autowired(required=false)
    private HttpApiService httpApiService;

    /**
     * HTTP 请求 调用汇文API获取用户信息接口 根据用户id （userId）
     */
    @ApiOperation("HTTP 请求 调用汇文API获取用户信息接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "T2020620", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "type", value = "0: 证件号；1：条码号; 2: 身份证号; 3: 一卡通号", required = false, defaultValue = "0", dataType = "String", dataTypeClass = String.class, paramType = "query"),
            @ApiImplicitParam(name = "institutionId", value = "10000001", dataType = "String", dataTypeClass = String.class)
    })
    @Log(title = "HTTP 请求 调用汇文获取用户信息接口", businessType = BusinessType.OTHER)
    @PostMapping("/getUserInfo")
    public AjaxResult getUserInfo(
            @RequestParam("id")String id,
            @RequestParam(required = false, defaultValue = "0") String type,
            @RequestParam("institutionId")String institutionId) {
        return success(httpApiService.getUserInfoById(institutionId,id,type));
        // 直接返回汇文的响应对象 但是很多接口的响应中 code 和 msg 未设置 因此还是使用比较简单的响应设置
        // JSONObject result=bookCommissionService.getUserInfoById(id);
        // return AjaxResult.success(result.getString("msg"), result.getJSONObject("data"));
    }


    /**
     * HTTP 请求 调用汇文API校验用户信息
     */
    @ApiOperation("HTTP 请求 调用汇文API校验用户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "T2020620", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "pw", value = "libsys999", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "type", value = "0: 证件号；1：条码号; 2: 身份证号; 3: 一卡通号", required = false, defaultValue = "0", dataType = "String", dataTypeClass = String.class, paramType = "query"),
            @ApiImplicitParam(name = "institutionId", value = "10000001", dataType = "String", dataTypeClass = String.class)
    })
    @Log(title = "HTTP 请求 调用汇文获取用户信息接口", businessType = BusinessType.OTHER)
    @PostMapping("/validUserInfo")
    public AjaxResult validUserInfo(
            @RequestParam String id,
            @RequestParam String pw,
            @RequestParam(required = false, defaultValue = "0") String type,
            @RequestParam("institutionId")String institutionId) {
        return success(httpApiService.validUserInfo(institutionId,id,pw,type));
    }

    /**
     * HTTP 请求 调用汇文API 获取读者当前委托请求信息（读者委托申请和委托划到信息查询）
     */
    @ApiOperation("HTTP 请求 调用汇文API获取读者当前委托申请信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "T2020620", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "type", value = "0: 证件号；1：条码号; 2: 身份证号; 3: 一卡通号", required = false, defaultValue = "0", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "institutionId", value = "10000001", dataType = "String", dataTypeClass = String.class)
    })
    @Log(title = "HTTP 请求 调用汇文API获取读者当前委托申请信息", businessType = BusinessType.OTHER)
    @PostMapping("/commissionRequest")
    public AjaxResult commissionRequest(
            @RequestParam String id,
            @RequestParam(required = false, defaultValue = "0") String type,
            @RequestParam("institutionId")String institutionId) {
        return success(httpApiService.commissionRequest(institutionId,id,type));
    }

    /**
     * HTTP 请求 调用汇文API 获取图书封面信息
     */
    @ApiOperation("HTTP 请求 调用汇文API 获取图书封面信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bibIdList", value = "图书id列表", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "isbnList", value = "图书ISBN列表", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "institutionId", value = "10000001", dataType = "String", dataTypeClass = String.class)
    })
    @Log(title = "HTTP 请求 调用汇文API 获取图书封面信息", businessType = BusinessType.OTHER)
    @PostMapping("/getBookCover")
    public AjaxResult getBookCover(
            @RequestParam(required = false) List<String> bibIdList,
            @RequestParam(required = false) List<String> isbnList,
            @RequestParam("institutionId")String institutionId) {
        return success(httpApiService.getBookCover(institutionId, bibIdList, isbnList));
    }

}
